<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
	<head>
		<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
		<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
		<script type="text/javascript"
			src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
		<link href="${approot}/resource/jquery/validate/jquery.validate.css"
			rel="stylesheet" type="text/css" />
		<link href="${approot}/resource/jquery/validate/style.css"
			rel="stylesheet" type="text/css" />
		<style type="text/css">
#popupcontent {
	position: absolute;
	visibility: hidden;
	overflow: hidden;
	border: 1pxsolid #CCC;
	background-color: #F9F9F9;
	border: 1pxsolid #333;
	padding: 5px;
}
</style>
		<script type="text/javascript">
	/* <![CDATA[ */
	jQuery(function() {
		jQuery("#c_money").validate( {
			expression : "if (VAL) return true; else return false;",
			message : "充入金额不能为空"
		});
		jQuery("#c_money").validate( {
			expression : "if (VAL>0) return true; else return false;",
			message : "充入金额不能小于0"
		});
		jQuery('#card').validated(function() {
			//alert("通过验证");
				do_add();
			});
	});
	/* ]]> */
</script>

		<script type="text/javascript">
	function do_add() {
		var str = $('#card').serializeObject();
		var jsons = $.toJSON(str);
		add_card(jsons);
	}

	function add_card(jsons) {
		$.ajax( {
			url : '${approot}/admin/person/recharge_card',
			dataType : 'json',
			contentType : 'application/json',
			data : jsons,
			type : 'post',
			beforeSend : function() {
				// $('#main').disabled='true';
		},
		error : function(request) {
			alert(S);
		},
		success : function(data) {
			if (data.msg == "error") {
				alert('系统异常，充值失败');
			}
			if (data.msg == "succ") {
				alert('充值成功');
				//		  window.opener.refresh(); 
			window.location.reload();
		}
	}
		});
	}

	function show_card_number(id) {
		$.ajax( {
			url : '${approot}/admin/person/get_card_list/' + id,
			dataType : 'json',
			contentType : 'application/json',
			data : null,//$.toJSON({'id':id}),
			type : 'post',
			beforeSend : function() {
				// $('#main').disabled='true';
			},
			error : function(request) {
				//alert(S);
			},
			success : function(data) {
			if (data.msg == "error") {
				alert('系统异常，获取用户卡列表失败');
			}
			if (data.msg == "succ") {

			}
			var popUp = document.getElementById("popupcontent");
//			popUp.style.top = "400px";
			popUp.style.left = "100px";
			popUp.style.width = 600 + "px";
/*			popUp.style.height = 100 + "px";
*/
			popUp.innerHTML = data.sb.toString();
			popUp.style.visibility = "visible";

		}
		});
	}

	function hidePopup()
	{
		var popUp = document.getElementById("popupcontent");
		popUp.style.visibility = "hidden";
		popUp.innerHTML = "";
	}
	
	function set_card_number(id,cardId,cardNumber){
		document.getElementById('to_card_number_'+id).value = cardNumber;
		document.getElementById('to_card_id_'+id).value = cardId;
	}
	
	function to_transfer_card(id){
	
		//要转账的金额
		var money = document.getElementById('card_money_'+id).value;
		
		//转入账号ID
		var toCardId = document.getElementById('to_card_id_'+id).value;
		var toCardNumber = document.getElementById('to_card_number_'+id).value;
		//转出账号ID
		var fromCardId = document.getElementById('from_card_id').value;
		
		//转出账号余额
		var yuan_money = document.getElementById('yuan_money').value;
		if(toCardNumber == '' || toCardId == ''){
			alert('请填写转入账号');
			return false;
		}
		if(money == ''){
			alert('请填写转入金额');
			return false;
		}
		if(yuan_money < money){
			alert('余额不足，无法转账');
			return false;
		}
		$.ajax( {
			url:'${approot}/admin/person/transfer_card/'+fromCardId+'/'+toCardId+'/'+money,
			dataType : 'json',
			contentType : 'application/json',
			data : null,
			type : 'post',
			beforeSend : function() {
				// $('#main').disabled='true';
				alert('aaaaa');
			},
			error : function(request) {
				//alert(S);
			},
			success : function(data) {
				if (data.msg == "error") {
					alert('转账失败，请检查转入账号是否正确');
				}
				if (data.msg == "succ") {
					alert('转账成功');
					window.location.reload();
				}
			
			}
		});
		
	}
</script>

	</head>
	<body style="background: #E8F5FE; padding: 15px 18px;" class="scroll_r">


		<form method="post"
			action="${approot}/admin/person/transfer_card_list" id="personBean">
			<table border="0" cellpadding="0" cellspacing="1" width="92%"
				align="center" class="tab_l">
				<tr>
					<td>
						<b>客户转账： <input type="hidden" name="personId" id="from_person_id"
								value="${person.personId }" /> <input type="hidden" id="from_card_id"
								name="cardId" value="${card.cardId }" /> </b>
					</td>

				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="1" width="92%"
				align="center" id="add_tab">
				<tr>
					<th>
						姓名：
					</th>
					<td>
						<input type="text" name="" value="${person.personName }" id="name">
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>
				<tr>
					<th>
						卡号：
					</th>
					<td>
						<input type="text" name="" value="${card.cardNumber}" id="number">
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>
				<tr>
					<th>
						余额：
					</th>
					<td>
						<input type="text" name=""
							value="<c:if test="${!empty card.money}">${card.money}</c:if><c:if test="${empty card.money}">0</c:if>"
							id="yuan_money">
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>

			</table>

<table><tr><td height="150"><div id="popupcontent"></div></td></tr></table>

			<table border="0" cellpadding="0" cellspacing="1" width="92%"
				align="center" id="add_tab">
				<tr>
					<th>
						用户编号：
					</th>
					<td>
						<input type="text" id="number" name="number"
							value="${personBean.number}" />
					</td>
					<th>
						用户名：
					</th>
					<td>
						<input type="text" id="name" name="name"
							value="${personBean.name}" />
					</td>
				</tr>
				<tr>
					<td colspan="4" style="text-align: center">
						<input type="submit" class="but" value="开始查询">
						<input type="button" class="but" onclick=
	formreset();;;;;;
value="重置条件">
					</td>
				</tr>
			</table>
		</form>
		<c:choose>
			<c:when test="${fn:length(list)<1}">
				<div align="center">
					<font color='red'>对不起,暂时没有找到符合条件的数据!</font>
				</div>
			</c:when>
			<c:otherwise>
				<table border="0" cellpadding="" cellspacing="1" align="center"
					width="92%" id="web_tab">

					<tr>

						<th>
							客户编号
						</th>
						<th>
							客户名称
						</th>

						<th>
							客户类型
						</th>
						<th>
							卡号
						</th>
						<th>
							金额
						</th>
						<th>
							操作
						</th>
					</tr>
					<c:forEach var="person" items="${list}">
						<tr>

							<td>
								${person.personNumber }
							</td>
							<td>
								${person.personName }
							</td>
							<td>
								<c:if
									test="${!empty person.personType && person.personType == 0}">零散户</c:if>
								<c:if
									test="${!empty person.personType && person.personType == 1}">商业户</c:if>
								<c:if
									test="${!empty person.personType && person.personType == 2}">集体户</c:if>
							</td>



							<td>
								<input type="text" id="to_card_number_${person.personId}" name=""
									value="" />
									<input type="hidden" id="to_card_id_${person.personId}" name=""
									value="" />
								<input type="button" class="but" value="查看"
									onclick="show_card_number('${person.personId}')" />
								
							</td>
							
							<td>
								<input type="text" style="width: 50%" name="" id="card_money_${person.personId}"/>
							</td>
							<td>
								<a href="#" onclick="to_transfer_card('${person.personId}')">转入</a>

							</td>
						</tr>
					</c:forEach>
				</table>

			</c:otherwise>
		</c:choose>











	</body>
</html>
